package listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import util.ProjectConstants;
import util.TimeCounter;

/**
 * Application Lifecycle Listener implementation class contextListener
 *
 */
@WebListener
public class contextListener implements ServletContextListener {

    /**
     * Default constructor. 
     */
    public contextListener() {
        // TODO Auto-generated constructor stub
    }

	/**
     * @see ServletContextListener#contextInitialized(ServletContextEvent)
     */
    public void contextInitialized(ServletContextEvent arg0) {
    	// get the context
    	ServletContext context = arg0.getServletContext();
    	
        // initialize the average add item counter and avg checkout counter
    	TimeCounter avgAddingCounter = new TimeCounter();
    	TimeCounter avgCheckout = new TimeCounter();
    	
    	context.setAttribute(ProjectConstants.AVGADDTIME, avgAddingCounter);
    	context.setAttribute(ProjectConstants.AVGCHECKOUT, avgCheckout);
        	
    }

	/**
     * @see ServletContextListener#contextDestroyed(ServletContextEvent)
     */
    public void contextDestroyed(ServletContextEvent arg0) {
        // TODO Auto-generated method stub
    }
	
}
